package files;

import io.Writer;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;

public class Link {

	static String intToString(int num, int digits) {
	    StringBuffer s = new StringBuffer(digits);
	    int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;
	    for (int i = 0; i < zeroes; i++) {
	        s.append(0);
	    }
	    return s.append(num).toString();
	}
	
	public static void makeLST() {
		
	}
	
	public static void main(String[] args) {
		String root1 = "K:\\(｡･｀ω´･｡)\\2d\\kemo\\artists";
		String root2 = "K:\\(｡･｀ω´･｡)\\2d\\kemo\\";

		String dest1 = "K:\\hardlink\\kemohomo\\artist";
		String dest2 = "K:\\hardlink\\kemohomo";
		
		String path = "";
		String imageList = "K:\\hardlink\\kemohomo\\image.lst";
		
		int i = 1;
		
		try {
			Writer.write_line("START", imageList, false);
			Writer.write_line("; ; = Comment. Do not edit. To be run as a script.", imageList, true);
			Writer.write_line("; File must have no format characters.", imageList, true);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			FileVisitor<Path> dirProcessor = new ProcessDirectory(root1, false);

			for(File d : ((ProcessDirectory) dirProcessor).getList()) {
				//System.out.println(d.getName());
				path = dest1+"\\"+Link.intToString(i, 7);
				System.out.println(path);
				//System.out.println(d.toPath());
				Files.createSymbolicLink(new File(dest1+"\\"+Link.intToString(i, 7)).toPath(), d.toPath());
				
				if(!d.getName().equals("artists")) {
					FileVisitor<Path> fileProcessor = new ProcessFile(d.getAbsolutePath(), true);
					
					for(File f : ((ProcessFile) fileProcessor).getList()) {
						//System.out.println(path+"\\"+f.getName());
						Writer.write_line(path+"\\"+f.getName(), imageList, true);
					}
				}
				
				//if(i == 0)
				/*for (int i = 0; i < name.length(); i++) {
				    char c = name.charAt(i);
				    if(Character.UnicodeBlock.of(c) != UnicodeBlock.BASIC_LATIN)
				    	name
					//System.out.println(Character.UnicodeBlock.of(b).toString());
					try {
						map.put(Character.UnicodeBlock.of(c), name);
					}
					catch (IllegalArgumentException e) {
						
					}
				}*/
				
				i++;
			}
			Writer.write_line("END", imageList, true);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
